from typing import List, Literal, Union
from pydantic import Field, BaseModel, validator
from package.fastapi.schema import Page, BatchId


class _HttpDevops(BaseModel):
    """HTTP"""
    scheme: Literal['http', 'https'] = Field('http', title='')
    path: str = Field('', title='')

    class Config:
        extra = 'allow'


class _SqlDevops(BaseModel):
    database: str = Field(None, title='')
    username: str = Field(None, title='')
    password: str = Field(None, title='')
    query: dict = Field(None, title='')


class _KafkaDevops(BaseModel):
    pass


class EditDevops(BaseModel):
    description: str = Field('-', title='数据源描述')
    configure: Union[_HttpDevops, _SqlDevops, dict] = Field(None, title='数据源配置')
    extra: dict = Field(None, title='数据源配置')
    heartbeat_interval: int = Field(0, title='心跳监测周期')
    metric_interval: int = Field(0, title='心跳监测周期')


class Devops(EditDevops):
    category: str = Field(..., title='数据源类型')
    name: str = Field(..., title='数据源名称')
    host: str = Field(..., title='数据源IP')
    port: int = Field(None, title='数据源端口')


class DevopsOut(Devops):
    id: str = Field(..., title='ID')

    class Config:
        orm_mode = True


class PageDevops(Page):
    data: List[DevopsOut] = Field(..., title='')


class ExternalOut(DevopsOut):
    pass


class PageExternal(Page):
    data: List[ExternalOut] = Field(..., title='')
